package com.lidroid.xutils.sample.menuapp.adaptor;

 
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.sample.BitmapHelp;
import com.lidroid.xutils.sample.R;
import com.lidroid.xutils.sample.menuapp.enty.Dish;
import com.lidroid.xutils.sample.menuapp.enty.Step;
/**
 * 
 * @author 洋洋 
 * 项目名称：xUtils框架结合SwipeRefreshLayout网络加载下拉刷新
 * 类 名 称：listview 适配器
 * 类 描 述：给listview 适配数据
 * 创 建 人：刘兴洋 Copyright
 * 创建时间：2014-12-20上午9:51:36
 *(c)刘兴洋-版权所有
 */
public class ListAdpter extends BaseAdapter {
	/*视图*/
	private LayoutInflater inflater;
	/*上下文*/
	private Context context;
	/*数据*/
	private List<Dish> list;
	/*图片展示对象*/
	private BitmapUtils bitmapUtils;
	
	public ListAdpter(Context context,BitmapUtils bitmapUtils,List<Dish> list) {
		super();
		this.inflater = LayoutInflater.from(context);
		this.context = context;
		this.bitmapUtils=bitmapUtils;
		this.list=list;
	}
	@Override
	public int getCount() {
		
		return list.size();
	}
	
	@Override
	public Object getItem(int arg0) {
		
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			  
			convertView = inflater.inflate(
					R.layout.activity_menu_list_item, null);
			holder.albumsIV = (ImageView) convertView
					.findViewById(R.id.albums_iv);
			holder.titleTV = (TextView) convertView
					.findViewById(R.id.title_tv);
			holder.tagsTV = (TextView) convertView
					.findViewById(R.id.tags);

			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
//		holder.albumsIV.setImageBitmap(menList.get(position)
//				.getAlbums());
		
		Dish dishData =list.get(position);
		holder.titleTV.setText(dishData.getName());
	 System.out.println("测试数据"+dishData.getName());
		holder.tagsTV.setText(dishData.getTags());
		//   holder.imgPb.setProgress(0);
		Step[] step=dishData.getSteps();
		 BitmapUtils bitmapUtils  = BitmapHelp.getBitmapUtils( context);
	        bitmapUtils.configDefaultLoadingImage(R.drawable.ic_launcher);
	        bitmapUtils.configDefaultLoadFailedImage(R.drawable.bitmap);
	        bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);
	         
	        bitmapUtils.display(holder.albumsIV, dishData.getAlbums());
	    	
//           bitmapUtils.display(holder.albumsIV, , new CustomBitmapLoadCallBack(holder));
		return convertView;
	}
	private class ViewHolder {
		ImageView albumsIV;
		TextView titleTV;
		TextView tagsTV;
	}
}
